home *** CD-ROM | disk | FTP | other *** search
- /*
- Undefine min and max, I'm going to substitute functions for them
- since I only use integers.
- */
-
- #ifdef min
- #undef min
- #endif
-
- #ifdef max
- #undef max
- #endif
-
- /*
- The following defines turn off specific features of the view program
- some of these features are interdependant so you may have to turn off
- more than one or turn on more than one to get the effect you are looking
- for.
- */
- #define VIEW_HAS_RAW 1 /* Hex and Bin modes */
- #define VIEW_HAS_MEMORY 1 /* Views memory as file */
- #define VIEW_HAS_DIR 1 /* Shows dir listing */
- #define VIEW_HAS_SEARCH 1 /* Search for text string */
- #define VIEW_HAS_GOTO 1 /* Goto line/pos/address */
- #define VIEW_HAS_NEWFILE 1 /* Select a new file while in view */
- #define VIEW_HAS_TILE 1 /* Tile windows when window added or deleted */
-
- #define TRUE 1
- #define FALSE 0
-
- /*
- These defines are for the keyboard scan codes, these are specific to the
- IBM-PC and can be found in the IBM-PC Technical Reference Manual
- */
- #define CURSOR_DOWN 80
- #define CURSOR_LEFT 75
- #define CURSOR_RIGHT 77
- #define CURSOR_UP 72
-
- #define CNTL_CURSOR_LEFT 115
- #define CNTL_CURSOR_RIGHT 116
- #define CNTL_PGUP 132
- #define CNTL_PGDN 118
- #define CNTL_HOME 119
- #define CNTL_END 117
-
- #define PGDN 81
- #define PGUP 73
- #define HOME 71
- #define END 79
-
- #define SHIFT_TAB 15
- #define TAB 9
- #define ESC 27
- #define BACKSPACE 8
- #define RETURN 13
-
- /*
- These are the four ways that the viewstack can be refreshed on the
- screen.
- */
-
- #define REFRESH_ALL 0 /* Undo all windows, Redo all windows */
- #define REFRESH_TOP 1 /* Undo top window, Redo top window */
- #define REFRESH_CONTENTS 2 /* Redo contents of top window */
- #define REFRESH_OFF 3 /* Undo all windows */
- #define REFRESH_NEXT 4
- #define REFRESH_PREV 5
-
- /*
- These are the ways that the text can scroll vertically
- */
- #define SCROLL_NONE 0
- #define SCROLL_DOWN 1
- #define SCROLL_UP 2
- #define SCROLL_PAGE_UP 3
- #define SCROLL_PAGE_DOWN 4
- #define SCROLL_HOME 5
- #define SCROLL_END 6
- #define SCROLL_RESET 7
- #define SCROLL_CLEAR 8
-
-
- /*
- These are defines for the limits of various parts of view
- */
- #define VIEW_MAX_LINE 264 /* Maximum logical "line" (bytes)*/
- #define VIEW_MAX_BINMODE 80 /* Maximum logical "line" in BINMODE (bytes)*/
- #define VIEW_MAX_HEXMODE 16 /* Maximum logical "line" in HEXMODE (bytes)*/
- #define VIEW_MAX_LONG 20 /* Maximum number of digits in ULONG as ascii */
- #define VIEW_BUF_SIZE 20480 /* Buffering factor */
- #define VIEW_LINE_VIEW 50 /* Number of lines to cache */
-
- #define VIEW_EOF (0xFFFF) /* VIEWFILE end of file indicator */
-
- #if VIEW_HAS_MEMORY
-
- #define VIEW_MEM_NAME "MEMORY" /* Special file name to indicate memory instead of file */
-
- #endif
-
- #if VIEW_HAS_DIR
-
- #define VIEW_DIR_WIDTH (view_cols/2)+4 /* Width of directory window */
- #define VIEW_DIR_HEIGHT (view_rows/2)+4 /* Height of directory window */
- #define VIEW_DIR_ROW ((view_rows/2)-(VIEW_DIR_HEIGHT+2)/2) /* Top row of directory window */
- #define VIEW_DIR_COL ((view_cols/2)-(VIEW_DIR_WIDTH+2)/2) /* Left col of directory window */
-
- #endif
-
- /*
- These are some types that are used in view
- */
-
- typedef unsigned long ULONG; /* an unsigned long just an alias */
- typedef unsigned char UCHAR; /* an unsigned char type */
- typedef unsigned int UINT; /* an unsigned int type */
-
-
- /* Struct to save screen regions in */
- typedef
- struct viewsave
- {
- int row,col,rows,cols; /* Coordinates and dimensions of region */
- UCHAR *buf; /* Data saved from that region */
- } VIEWSAVE;
-
- /* Struct for file buffering and control */
- typedef
- struct viewfile
- {
- UCHAR *fname; /* file name */
- int fh; /* file handle or VIEW_MEM_HDL */
- ULONG pos; /* position of "memory" or file pointer */
- ULONG end; /* end of the file */
- int idx; /* next character in buffer */
- int len; /* number of characters in buffer */
- UINT lmode; /* formatting mode for lines */
- UCHAR buf[VIEW_BUF_SIZE]; /* buffer */
- } VIEWFILE;
-
- typedef /* Struct for managing views on screen */
- struct view
- {
- int row,col,rows,cols; /* Current position and dimensions of view */
- int coff; /* column offset into each line */
- ULONG pos[VIEW_LINE_VIEW]; /* position in viewfile of lines */
- UCHAR *lines[VIEW_LINE_VIEW]; /* lines currently in view */
- VIEWFILE *vf; /* file control struct for this view */
- VIEWSAVE *save; /* screen region covered by view */
- struct view *next; /* next view in chain (circular) */
- struct view *prev; /* prev view in chain (circular) */
- } VIEW;
-
- #if VIEW_HAS_DIR
-
- typedef /* Struct for directory list */
- struct dirlist
- {
- UCHAR *line; /* text line for directory list */
- struct dirlist *prev; /* prev line (NULL terminated) */
- struct dirlist *next; /* next line (NULL terminated) */
- } DIRLIST;
-
- #endif
-
- extern VIEW *viewstack; /* pointer to the bottom view on screen */
-
- extern UCHAR _far *screen; /* pointer to display ram */
-
- #if VIEW_HAS_MEMORY
- #define VIEW_MEM_HDL -1
- /* huge 0 pointer to memory */
- extern UCHAR _huge *memory;
- #endif
- /* characters used in hex/dec conversion routines */
- extern UCHAR hexdigits[];
-
- extern int view_offset; /* current offset into display memory */
- extern int view_attr; /* current display attribute */
- extern int view_is_mono; /* flag indicates mono (TRUE) or color (FALSE) */
- extern int view_cols;
- extern int view_rows;
-
- #define VIEW_TEXT_MODE 0 /* TRUE to treat display as \n termed text lines */
-
- #if VIEW_HAS_RAW
-
- #define VIEW_BIN_MODE 1 /* if TRUE display 80 column unformatted records with file offset on left */
- #define VIEW_HEX_MODE 2 /* if TRUE display 16 byte hex formatted display with file offset on left and ascii on right */
-
- #endif
-
- extern UCHAR *view_line; /* line input buffer */
-
- #if VIEW_HAS_DIR
-
- extern UCHAR *view_curdir; /* current directory when view entered */
-
- #endif
-
- /*
- Array of attributes for color and monochrome displays
- */
-
- extern int view_attr_list[2][5];
-
- #define ACTIVE_WINDOW (view_attr_list[view_is_mono][0])
- #define INACTIVE_WINDOW (view_attr_list[view_is_mono][1])
- #define ERROR_MESSAGE (view_attr_list[view_is_mono][2])
- #define GET_STRING (view_attr_list[view_is_mono][3])
- #define GET_STRING_CURSOR (view_attr_list[view_is_mono][4])
-
-
- /*
- Function Prototypes
- */
- int max( int x, int y);
- int min ( int x, int y);
- int gcd( int a, int b );
-
- VIEWSAVE *view_getsave( int row,int col,int rows,int cols );
- void view_putsave( VIEWSAVE *save );
- void view_restore( VIEW *trav );
- void view_frame( UCHAR *title,int row,int col,int rows,int cols );
-
- void view_goto(int row,int col);
- void view_putc( int ochar );
- void view_fill(int fill, int count);
- void view_puts(UCHAR *str, int len);
- int view_gets( int row,int col, int len, UCHAR *str);
- int view_prompt( UCHAR *title,UCHAR *prompt, UCHAR *retbuf, int retlen );
-
- void _far view_errfunc();
- void view(void);
- void view_save( VIEW *trav );
- void view_refresh(int refresh_mode);
- void view_new( UCHAR *fname, int row,int col,int rows,int cols );
- void view_tile( void );
- void view_delete( void );
- void view_quit( void );
- void view_error( int isfatal, UCHAR *msg );
- void view_scroll( VIEW *current, int mode );
- UCHAR *view_strdup( UCHAR *str);
- int view_packbuf( UCHAR *buf, int size );
- void view_unpackbuf( UCHAR *buf, int row, int col, int rows, int cols );
-
-
- #if VIEW_HAS_NEWFILE
- int view_newfile( void );
- #endif
-
- #if VIEW_HAS_SEARCH
- int view_search( void );
- #endif
-
- int view_getvidmode( void );
-
- ULONG view_seek( VIEWFILE *vf, long pos, int base );
- ULONG view_tell( VIEWFILE *vf );
- UINT view_getl_bwd( VIEWFILE *vf, UCHAR *line, int max );
- UINT view_getl_fwd( VIEWFILE *vf, UCHAR *line, int max );
- UINT view_getc_fwd( VIEWFILE *vf );
- UINT view_getc_bwd( VIEWFILE *vf );
- int view_read_fwd( VIEWFILE *vf );
- int view_read_bwd( VIEWFILE *vf );
- VIEWFILE *view_open( UCHAR *fname );
- void view_close( VIEWFILE *vf );
-
- #if VIEW_HAS_RAW
-
- UINT view_getl_raw( VIEWFILE *vf, UCHAR *line, int dir );
- UCHAR *view_ultoa( ULONG num, int base, int wide, int fill );
-
- #endif
-
- #if VIEW_HAS_GOTO
-
- ULONG view_atoul( UCHAR *num, int base );
- void view_goto_line( void );
-
- #endif
-
- #if VIEW_HAS_DIR
-
- void view_dirdisp( DIRLIST *dir );
- int view_dir( UCHAR *name );
- DIRLIST *view_getlist ( void );
- DIRLIST *view_freelist( DIRLIST *dir );
- DIRLIST *view_addline(DIRLIST *dir, struct find_t *file);
- void view_fmtline(UCHAR *line, struct find_t *file);
-
- #endif
-
-